﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class LoginPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
        using (SqlConnection con = new SqlConnection(CS))
        {
            con.Open();
            string checkuser = "SELECT COUNT(*) FROM SUBADMINS WHERE USERNAME='" + TextBoxUserNameLogin.Text + "'";
            SqlCommand com = new SqlCommand(checkuser, con);
            int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
            con.Close();
            if (temp == 1)
            {
                con.Open();
                string checkPasswordQuery = "SELECT LOGPASS FROM SUBADMINS WHERE USERNAME='" + TextBoxUserNameLogin.Text + "'";
                SqlCommand passComm = new SqlCommand(checkPasswordQuery, con);
                string password = passComm.ExecuteScalar().ToString().Replace(" ","");
                if (password == TextBoxPasswordLogin.Text)
                {
                    Session["New"] = TextBoxUserNameLogin.Text;
                    Response.Redirect("DivAdminHome.aspx");
                }
                else
                {
                    LabelLoginStatus.Text = "Password is incorrect";
                }
            }
            else
            {
                LabelLoginStatus.Text = "Username is incorrect";
            }

        }

    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("RegisterPage.aspx");
    }
}

